#include <sys/time.h>
#include "Graph.h"
#include "GraphLoader.h"
#include "Path_Hop.h"
#include "hlss.h"
#include <string>
#include "Interval.h"

static void usage()
{
	cout << 
		"Usage Description:\n"
		"./path_hop filename option\n"
		"options:\n"
		"1 : Path Hop\n"
		"2 : HLSS on full Transitive Closure\n"
		"3 : HLSS on Residual Transitive Closure\n";
	
}

int main(int argc, char* argv[])
{
	if (argc < 3)
	{
		usage();
		return 0;
	}
	char* filename = argv[1];
	ifstream infile(filename);
	if (infile == NULL)
	{
		cout << "ERR_01: File Can not be opened!" << endl;
		return -1;
	}
	/*
	 *proc_type: indicate which program to run
	 * 1 = path_hop
	 * 2 = HLSS on full TC
	 * 3 = HLSS on RTC
	 */
	int proc_type = atoi(argv[2]);
	int query_size = 100000;
	Timer timer;
	Graph g;
	GraphLoader::readGraph(infile, g);
	cout << "---INPUT:---" << endl;	
	cout << "File name: " << filename << endl;
	int node_count = num_vertices(g);
	cout << "# of vertices: " << node_count << "       # of edges: " << num_edges(g);
	if ( proc_type == 1)
	{
		cout << "   Alg: Path Hop" << endl;
		timer.start();
		Path_Hop ph(g);
		ph.create_label();
		cout << "Path Hop Index Construction time:" << timer.stop() << endl;
		ph.batch_query(query_size);
	}	
	else if (proc_type == 2)
	{
		cout << "   Alg: HLSS on full TC" << endl;
		timer.start();
		hlss hl(g, node_count, NULL);
		int size = hl.create_label();
		cout << endl << "Index size: " << size;
		cout << "  Construction time: " << timer.stop() << endl;
		hl.batch_query(query_size);
	}
	else if(proc_type == 3)
	{
		cout << "  Alg: HLSS on Residual TC" << endl;
		timer.start();
		Path_Hop ph(g);
		int size  = ph.hlss_on_utc() + node_count * 2;
		cout << endl << "Index size: " <<  size;
		cout << "   Construction time:" << timer.stop() << endl;
		ph.hl->batch_query(query_size);
	}
	return 0;
}

